package com.xsz.controller;

import com.xsz.entity.Position;
import com.xsz.entity.User;
import com.xsz.service.DTODao;
import com.xsz.service.PositionService;
import com.xsz.util.ResultVOUtil;
import com.xsz.vo.ResultVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @Date:2020/3/25 17:13
 * @Author:zzc
 * 职位
 */
@RestController
@RequestMapping("/position")
@Api(value = "职位接口")
public class PositionController {

    @Resource
    PositionService positionService;

    @Resource
    DTODao dtoDao;

    @Resource
    private RestTemplate restTemplate;

    //根据简历表和职位表显示查询到的申请人名字和申请的职位
    @ApiOperation(value = "根据简历表和职位表显示查询到的申请人名字和申请的职位")
    @GetMapping("showAllResumeCrebyAndName")
    public ResultVO showAllResumeCrebyAndName() {
        return ResultVOUtil.success(dtoDao.showCreatePname());

    }

//    /**查询所有职位名称**/
//    @GetMapping("showByTid/{tid}")
//    public ResultVO showByTid(@PathVariable("tid") String tid){
//        return ResultVOUtil.success(positionService.showByTid(tid));
//    }
//
//    /**查询相关职位信息**/
//    @GetMapping("showByNameAndTid/{name}/{tid}")
//    public ResultVO showByNameAndTid(@PathVariable("name") String name, @PathVariable("tid") String tid){
//        List<Position> p = positionService.showByNameAndTid(name, tid);
//        return ResultVOUtil.success(p);
//    }

    /**查询所有职位信息**/
    @GetMapping("showAll")
    public ResultVO showAll(){
        return ResultVOUtil.success(positionService.showAll());
    }



    /**添加职位**/
    @PostMapping("addPosition")
    public ResultVO addPosition(@RequestBody Position position, HttpServletRequest request){
        return ResultVOUtil.success(positionService.addPosition(position, (User)request.getSession().getAttribute("loginuser")));
    }

    /**修改职位**/
    @PostMapping("editPosition")
    public ResultVO editPosition(@RequestBody Position position){
        return ResultVOUtil.success(positionService.editPosition(position));
    }

    /**删除职位**/
    @PostMapping("deletePosition/{id}")
    public ResultVO deletePosition(@PathVariable("id") String id){
        positionService.deletePosition(id);
        Map<String, String> result = new HashMap<>();
        result.put("result", "成功");
        return ResultVOUtil.success(result);
    }
    /**根据createBy查询所有职位**/
    @GetMapping("showAllByCreateById")
    public ResultVO showAllByCreateById(HttpServletRequest request){
        return ResultVOUtil.success(positionService.showAllByCreateById(((User)request.getSession().getAttribute("loginuser")).getId()));
    }
    /**根据id查询职位**/
    @GetMapping("showById")
    public ResultVO showById(@PathVariable("id") String id){
        return ResultVOUtil.success(positionService.showById(id));
    }

    /**显示所有的技能**/
    @GetMapping("showAllSkill")
    public ResultVO showAllSkill(HttpServletRequest request) {
        return this.restTemplate.getForObject("http://USERCENTER/dict/get?id=2", ResultVO.class);
    }

    /**显示所有的职位类别**/
    @GetMapping("showAllPositionType")
    public ResultVO showAllPositionType(HttpServletRequest request) {
        return this.restTemplate.getForObject("http://USERCENTER/dict/get?id=1", ResultVO.class);
    }

    /**申请职位**/
    @GetMapping("applyPosition/{selectresumeId}/{selectpositionId}")
    public ResultVO applyPosition(HttpServletRequest request,@PathVariable("selectresumeId") String selectresumeId,@PathVariable("selectpositionId") String selectpositionId) {
        return this.restTemplate.getForObject("http://USERCENTER/dict/get?id=1", ResultVO.class);
    }

    /**分页返回所有职位信息**/
    @ApiOperation(value = "分页返回所有职位信息")
    @GetMapping("showAll2/{page}/{limit}")
    public ResultVO showAll2(@PathVariable("page") String page, @PathVariable("limit") String limit){
        return ResultVOUtil.success(positionService.showAll2(page, limit));
    }
}